<template>
  <div>
    <ul>
      <li v-for="message in messages" :key="message.id"><!-- 如果我们遍历的数据有标识属性就用标识属性作为key -->
        <RouterLink :to="`/home/message/detail/${message.id}`">{{message.title}}</RouterLink>
        <button @click="pushShow(message.id)">push查看</button>
        <button @click="replaceShow(message.id)">replace查看</button>
      </li>
    </ul>
<!--    <button @click="backHandler">返回</button>-->
    <button @click="$router.back()">返回</button>
    <div>
      <RouterView/>
    </div>
  </div>
</template>

<script>
  export default {
    name: "Message",
    data() {
      return {
        messages: []
      }
    },
    mounted() {
      // 模拟异步获取数据
      setTimeout(() => {
        console.log("xxxxxx");
        this.messages = [
          {
            id: 1,
            title: 'message001'
          },
          {
            id: 2,
            title: 'message002'
          },
          {
            id: 3,
            title: 'message003'
          },
        ]
      }, 1000);
    },
    methods: {
      pushShow(id) {
        console.log(this);
        this.$router.push(`/home/message/detail/${id}`);
      },
      replaceShow(id) {
        this.$router.replace(`/home/message/detail/${id}`);
      },
      backHandler() {
        this.$router.back();
      }
    }
  }
</script>

<style scoped>

</style>
